package cn.itcast.web.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
cookie细节操作:
3.cookie能不能保存中文？
 *在tomcat 8之间cookie中不能直接存储中文数据。
    *需要将中文数据转码--一般采用URL编码。
 *在tomcat 8之后cookie支持中文数据。
* */
@WebServlet("/cookieservletDemo5")
public class CookieServletDemo5 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //1.创建Cookie对象
        Cookie cookie=new Cookie("msg","你好，cookie");
        //2.发送Cookie到浏览器
        response.addCookie(cookie);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
